﻿namespace HiMap.MapControls.Tools
{
    using HiMap.Carto;
    using HiMap.Geometry;
    using HiMap.MapControls;
    using HiMap.MapControls.Tools.Frm;
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;

    public class ToolInfo : ToolClass
    {
        protected override void OnMouseDown(object sender, MouseEventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            List<IFeatureCursor> list = new List<IFeatureCursor>();
            ISpatialFilter filter = new SpatialFilterClass();
            filter.Buffer = 20;
            filter.QType = QueryType.Pixel;
            IPoint point = new PointClass();
            point.X = e.X;
            point.Y = e.Y;
            filter.Geometry = point;
            FrmInfo info = new FrmInfo(false);
            bool flag = false;
            for (int i = 0; i < base.Map.Map.LayerCount; i++)
            {
                if (base.Map.Map.GetLayer(i).Visible)
                {
                    IFeatureCursor cur = ((IFeatureClass) base.Map.Map.GetLayer(i).Class).Search(filter);
                    cur.Flush();
                    list.Add(cur);
                    if (!flag && (cur.Next() != null))
                    {
                        flag = true;
                    }
                    info.LoadData(cur);
                }
            }
            Cursor.Current = Cursors.Default;
            base.Map.Flash(list, Color.Red, 3, 0x1f5);
            if (flag)
            {
                info.ShowDialog();
            }
            else
            {
                MessageBox.Show(Setup.GetInfo("ToolInfoMessage1"));
            }
        }
    }
}

